
package com.shycloud.mido.basic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shycloud.mido.basic.api.entity.BasSensitiveWords;
import com.shycloud.mido.basic.mapper.BasSensitiveWordsMapper;
import com.shycloud.mido.basic.service.BasSensitiveWordsService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 敏感词表 服务实现类
 *
 * @author yyy
 * @date 2019-02-26 16:32:57
 */
@Service
@AllArgsConstructor
public class BasSensitiveWordsServiceImpl extends ServiceImpl<BasSensitiveWordsMapper, BasSensitiveWords> implements BasSensitiveWordsService {

	private final BasSensitiveWordsMapper basSensitiveWordsMapper;

	/**
	 *  保存敏感词汇
	 * @param basSensitiveWords
	 */
	@Override
	public boolean saveWords(BasSensitiveWords basSensitiveWords){
		List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
		String[] text =  basSensitiveWords.getText().split("\n");
		for(int i=0; i < text.length; i++){
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("text",text[i]);
			map.put("createUser",basSensitiveWords.getCreateUser());
			list.add(map);
		}
		return basSensitiveWordsMapper.saveWords(list);
	}


	/**
	 * 查询敏感词汇是否存在
	 * @param text
	 * @return
	 */
	@Override
	public Integer selByText(String text){
		return basSensitiveWordsMapper.selByText(text);
	}

}
